package com.oreilly.ez.base;

import com.oreilly.ez.entity.BaseEntity;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Interceptor;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;

import java.io.Serializable;

public class HibernateInterceptor extends EmptyInterceptor {

    @Override
    public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {

        System.out.println("###HibernateInterceptor: ");
        System.out.println(entity);

        if(entity instanceof BaseEntity){

            BaseEntity baseEntity = (BaseEntity) entity;
            Integer sid = baseEntity.getSid();
            if(sid != null){
                System.out.println("update");
            }
        }
        System.out.println(id);

        return super.onSave(entity, id, state, propertyNames, types);
    }
}
